/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { Descriptions, Space } from 'antd';
import { replaceKeys, statusMap } from '../_utils';

const AuditContent: React.FC<any> = (props) => {
  const { record, handleJump } = props;

  const { brand, user_type, create_time, approval_time, approver, cm_phone, status } = record;
  const user_info = JSON.parse(record.user_info || '{}');
  const send_info = JSON.parse(record.send_info || '{}');
  const data_info = JSON.parse(record.data_info || '{}');
  const { regDayDiff, YZMC, YZDZ } = user_info;
  const {
    total = 0,
    starPercent = 0,
    successPercent = 0,
    pass = 0,
    reject = 0,
    daojian = 0,
    paijian = 0,
    toudi = 0,
    chuku = 0,
    ruku = 0,
    todaySent = 0,
    thisCount = 0,
  } = data_info;
  const { template } = send_info;
  const templateData = { ...send_info, ...user_info };
  return (
    <Space direction='vertical'>
      <Descriptions column={1} size='small'>
        <Descriptions.Item label='注册'>{regDayDiff}天前</Descriptions.Item>
        {brand === 'dak' ? (
          <>
            <Descriptions.Item label='名称'>{YZMC}</Descriptions.Item>
            <Descriptions.Item label='地址'>{YZDZ}</Descriptions.Item>
          </>
        ) : null}
        <Descriptions.Item label='近七天数据'>
          短信{total}（
          {user_type === 'untrusted' ? `脱敏${starPercent}%，成功${successPercent}%，` : null}已通过
          {pass}批，已拒绝{reject}批）
          {user_type === 'untrusted'
            ? brand === 'dak'
              ? `入库${ruku} 出库${chuku}`
              : `到件${daojian} 派件${paijian} 投递${toudi}`
            : null}
        </Descriptions.Item>
        <Descriptions.Item>
          <span onClick={handleJump.bind(null, record)} style={{ cursor: 'pointer' }}>
            当日已发<a>{todaySent}</a>
          </span>
          ， 本批{thisCount}条<span style={{ marginLeft: 10 }}>提交时间：{create_time}</span>
        </Descriptions.Item>
        <Descriptions.Item label='短信内容'>
          <div
            dangerouslySetInnerHTML={{
              __html: replaceKeys(template, templateData, ['DH', 'NO', 'YZDZ', 'LOCATION']),
            }}
          />
        </Descriptions.Item>
        {approver ? (
          <Descriptions.Item>
            <span>{approval_time}</span>
            <span style={{ margin: '0 10px' }}>
              {approver}({cm_phone})
            </span>
            <span>{(statusMap && statusMap[status]?.label) || ''}</span>
          </Descriptions.Item>
        ) : null}
      </Descriptions>
    </Space>
  );
};

export default AuditContent;
